package com.ubxtech.gateway.auth;

import com.ubxtech.core.context.ContextToken;
import com.ubxtech.core.dto.AuthHeaderDTO;

import java.util.HashSet;
import java.util.Set;

/**
 * 自定义实现类,校验token或者按sign方式鉴权,token校验可以调用其它服务校验
 * @author Victor.Xiao
 * @since 2023-08-29 20:00
 **/
public interface GatewayLoginAuthService {
    /**
     * 鉴权
     * @author Victor.Xiao
     * @since 2023-08-29 20:32
     * @param authHeaderDTO authHeaderDTO
     * @return com.ubxtech.core.context.ContextToken
    */
    ContextToken auth(AuthHeaderDTO authHeaderDTO);

    /**
     * 接口鉴权,先要看path是不是要接口鉴权,不需要接口鉴权就直接返回true
     * @author Victor.Xiao
     * @since 2023-09-05 16:50
     * @param serviceId serviceId,对应的application.name
     * @param path path,当前的path
     * @param permissions permissions,已经授权的url
     * @return boolean
    */
    boolean hasApiPermission(String serviceId, String path, Set<String> permissions);


    /**
     * 获取内部api列表
     * @author Victor.Xiao
     * @since 2023-09-05 16:50
     * @param serviceId serviceId,对应的application.name
     * @return java.util.Set<java.lang.String>
     */
    default Set<String> getInnerApiList(String serviceId) {
        return new HashSet<>();
    }
}
